<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>其他组件通信的方式</title>
</head>
<body>
    <div id="app">
        <!-- 使用组件 -->
        <App></App>

    </div>
    <script src="vue.js"></script>
    <script>
        Vue.component('B',{
            data(){
                return{
                    count:0
                }
            },
            inject:['msg'],
            created(){
                console.log(this.msg);
            },
            template:`
                <div>
                    {{msg}}
                </div>
            `,
        })
        Vue.component('A',{
            data(){
                return{

                }
            },
            created(){
                console.log(this.$parent.$parent);
            },
            template:`
                <div>
                    <B></B>
                </div>
            `
        })
        const App={
            data(){
                return{
                    title:'老爹'
                }
            },
            provide(){
                return{
                    msg:'老爹的数据'
                }
            },
            template:`
                <div>
                    <A></A>
                </div>
            `
        }
        new Vue({
            el:'#app',
            data:{

            },
            components:{
                App
            }
        })
    </script>
</body>
</html>